<?php 
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
//require_once ROOT_PATH . '/lib/models/skillmatrix/SkillExpertise.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillGroup.php';
$empList = EmpInfo::getEmpSkillInfo();
$baseURL = './CentralController.php?skillMatrixcode=SkillMatrix';
$skillset = array("None","Basic","Intermadiate","Expert");
?>
<script type="text/javascript">
 function returnAdd() {
		
		document.standardView.action = '<?php echo $baseURL;?>&action=Export';
		document.standardView.submit();
}

function returnSearch() {
		document.standardView.action = '<?php echo $baseURL;?>&action=Summary';
		document.standardView.submit();
}

</script>
 
<h2><?php echo "Skill Matrix"; ?><hr/></h2>
<form id="standardView" name="standardView" method="post" action="<?php echo $baseURL;?>&action=Summary">
<div style="padding: 6px;">
				<img 
					title="Export" 
					alt="Export"
					src="../../themes/beyondT/pictures/btn_export.gif" 
					style="border: none;"
					onclick="returnAdd();"
					onmouseout="this.src='../../themes/beyondT/pictures/btn_export.gif';" 
					onmouseover="this.src='../../themes/beyondT/pictures/btn_export.gif';" />						
</div>

<table style="margin-left: 3px;">
<tr>
	
	<td >						
		<select name="grouptype" id="grouptype" onchange="returnSearch();" >
		<?php if(!isset($records['grouptype']) || $records['grouptype']==''){ ?>
		<option value="" >-Select group type-</option>	
		<option value="1" >Developer</option>
		<option value="2" >QA</option>
		<?php } elseif($records['grouptype']==1){ ?>
		<option value="" >-Select group type-</option>	
		<option selected value="1" >Developer</option>
		<option value="2" >QA</option>
		<?php }else{ ?>
		<option value="" >-Select group type-</option>	
		<option value="1" >Developer</option>
		<option selected value="2" >QA</option>
		<?php } ?>
		</select>
	</td>
	
	<td >						
		<select name="skillgroup" id="skillgroup" onchange="returnSearch();" >
		<option value="" >-Select skill group-</option>	
		<?php
		
			$allGroups = SkillGroup::getAll();
			for($m=0;$m< count($allGroups);$m++) {
				if($records['skillgroup'] && $records['skillgroup'] == $allGroups[$m]->getId() ) {
					echo "<option selected value='" . $allGroups[$m]->getId() ."'>".$allGroups[$m]->getSkillGroupName()."</option>";
				} else {
						echo "<option value='" . $allGroups[$m]->getId() ."'>".$allGroups[$m]->getSkillGroupName()."</option>";			
				}
								
			}
		?>
		</select>
	</td>
	<td >
		<?php if($records['lastupdate']==1){ ?>						
			<input type="checkbox" checked name="lastupdate" id="lastupdate" value="1" onchange="returnSearch();"> Show latest update
		<?php }else{ ?>
			<input type="checkbox" name="lastupdate" id="lastupdate" value="1" onchange="returnSearch();"> Show latest update
		<?php }?>
	</td>
</tr>
</table>
	
<table border="0" cellpadding="0" cellspacing="0"  >
   <thead>
   <!-- 
  	<tr>
		<th class="tableTopLeft"></th>    	
    	<th class="tableTopMiddle" ></th>
    	<th class="tableTopMiddle" ></th>
    		<? for($i=0; $i<count($empList);$i++){ ?>
    			<th class="tableTopMiddle" ></th>
		<?php } ?>                	
		<th class="tableTopRight"></th>
	</tr>
	 -->
	<tr >
		<th class="tableMiddleLeft" ></th>		
    	<th class="tableMiddleMiddle" rowspan="2"  style="border-top:1px solid #D0D0D0;border-right:1px solid #D0D0D0;border-left:1px solid #D0D0D0;"><?php echo "Group"; ?></th>
    	<th class="tableMiddleMiddle" rowspan="2" style="width: 300px;border-top:1px solid #D0D0D0;border-right:1px solid #D0D0D0;" ><?php echo "Skill Expertise"; ?></th>
    		<? for($i=0; $i<count($empList);$i++){ ?>
    			<th class="tableMiddleMiddle" style="border-top:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
    				<?php echo $empList[$i][1]." ".$empList[$i][4]." ".$empList[$i][3]; ?>    					
    			</th>
		<?php } ?>
		<th class="tableMiddleMiddle" style="border-top:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
    		Total    					
    	</th>
				
		<th class="tableMiddleRight"></th>
	</tr>
	<?php /* ?>
	<tr>
	<th class="tableMiddleLeft"></th>		
	<? for($j=0; $j<count($empList);$j++){ ?>
    			<th class="tableMiddleMiddle" >
    				    <1<!--  <span style="-moz-transform: rotate(-90deg);" ><1</span>-->					
    			</th>
    			<th class="tableMiddleMiddle" >
    				    1-3<!-- <span style="-moz-transform: rotate(-90deg);" >	1->3</span>-->					
    			</th>
    			<th class="tableMiddleMiddle" >
    				    3-5<!-- <span style="-moz-transform: rotate(-90deg);" >	3->5</span>		-->				
    			</th>
    			<th class="tableMiddleMiddle" >
    				     >5<!-- <span style="-moz-transform: rotate(-90deg);" > >5	</span>				-->
    			</th>
		<?php } ?>
		<th class="tableMiddleRight"></th>
	</tr>		
	 <?php */ ?>
  </thead>
  
  
  <tbody >
   
  <?php 
  	$array = $records['skillmatrix'];
  	
  	if (is_array($array) && count($array)>0) { 
  	$j=0;	
  	for($m=0;$m<count($array);$m++) {
  		if(!($j%2)) {
				$cssClass = 'odd';
			 } else {
			 	$cssClass = 'even';
			 }
			 $j++;
  		$record = $array[$m];
  		$skillExpertises = $record->getSkillExpertise($record->getId());
  		if(count($skillExpertises)>0){
  		$skillExpertise1 = $skillExpertises[0]; 	
  	?>		
  <tr class="skillMatrix">
	<td class="tableMiddleLeft" rowspan="<?php echo count($skillExpertises); ?>"></td>  
    <td class="<?php echo $cssClass; ?>" rowspan="<?php echo count($skillExpertises); ?>" style="border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;border-left:1px solid #D0D0D0;"><?php echo $record->getSkillGroupName(); ?></td>
    
    <td class="<?php echo $cssClass; ?>" style="width: 300px; border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;" ><?php echo $skillExpertises[0]->getSkillExpertiseName(); ?></td>
     
        <?php
        	$total=0;
        	$basic=0;
        	$intermediate=0;
        	$expertise=0;         	  
        	for($k=0; $k<count($empList);$k++){        		
        		$userSkills = $skillExpertise1->getUserSkills($skillExpertise1->getId(),$empList[$k][0]);
        		if(count($userSkills)>0){
        			$level=$userSkills[0]->getSkillUserValue();
        			$value='';
        			if($level<4){
        				$value .=  $skillset[$level];
        				if($level==1)
        					$basic++;
        				elseif($level==1)
        					$intermediate++;
        				else
        					$expertise++;		
        			}
        			if($userSkills[0]->getSkillUserDateSubmit()!= '0000-00-00 00:00:00' && $records['lastupdate']==1)
						$value .= "(".date('M d,y',strtotime($userSkills[0]->getSkillUserDateSubmit())).")" ;
        			$total++;
        		}
				else         			
        			$value = '';
        	?> 
        	
            <td class="<?php echo $cssClass; ?>" style="text-align: center;border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
            	<?php echo $value ;  ?>
            </td>           
            <?php } ?>
       <td class="<?php echo $cssClass; ?>" style="text-align: center;border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
            	<?php echo "<span style='font-weight:bold;color:red;'>".$total."</span>(Basic:<span style='font-weight:bold;'>$basic</span>,Intermediate:<span style='font-weight:bold;'>$intermediate</span>,Expertise:<span style='font-weight:bold;'>$expertise</span>)" ;  ?>
       </td>  
 </tr>
  <? 
  if(count($skillExpertises)>1){
  for($n=1;$n<count($skillExpertises);$n++){
  	 $skillExpertise = $skillExpertises[$n];  	 
  ?>   
  <tr class="skillMatrix">
    <td class="<?php echo $cssClass; ?>" style="border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;"><?php echo $skillExpertises[$n]->getSkillExpertiseName(); ?></td>
    <?php
    $total2=0;
    $basic=0;
    $intermediate=0;
    $expertise=0;  
    for($l=0; $l<count($empList);$l++){
    	$userSkills = $skillExpertise->getUserSkills($skillExpertise->getId(),$empList[$l][0]);
    	if(count($userSkills)>0){
    		$level=$userSkills[0]->getSkillUserValue();
        	$value = '';
        	if($level<4){
        		$value .= $skillset[$level];
        		if($level==1)
        					$basic++;
        				elseif($level==1)
        					$intermediate++;
        				else
        					$expertise++;
        	}
        	if($userSkills[0]->getSkillUserDateSubmit()!= '0000-00-00 00:00:00' && $records['lastupdate']==1)
				$value .= "(".date('M d,y',strtotime($userSkills[0]->getSkillUserDateSubmit())).")" ;
        	$total2++;
    	}
		else         			
        	$value = ''; 
    ?> 
    <td class="<?php echo $cssClass; ?>" style="text-align: center; border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
    <?php echo $value ;  ?>
    </td>
    
    <?php } ?>
     <td class="<?php echo $cssClass; ?>" style="text-align: center;border-bottom:1px solid #D0D0D0;border-right:1px solid #D0D0D0;">
            	<?php echo "<span style='font-weight:bold;color:red;'>".$total2."</span>(Basic:<span style='font-weight:bold;'>$basic</span>,Intermediate:<span style='font-weight:bold;'>$intermediate</span>,Expertise:<span style='font-weight:bold;'>$expertise</span>)" ;  ?>
       </td> 
      

  </tr>
<?php } 
  }
?>
  
  <?php } 
  	}
  }
  ?>
  
  </tbody>
 <!-- 
  <tfoot>
  	<tr>
		<td class="tableBottomLeft"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomMiddle"></td>	
			<? for($i=0; $i<count($empList);$i++){ ?>
    			 	<td class="tableBottomMiddle"></td>	
		<?php } ?>				
		<td class="tableBottomRight"></td>
	</tr>
  </tfoot>
   -->
</table>

